package com.lzdongrui.common.utils.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

/**
 * <p>
 *
 * </p>
 *
 * @author huanghemao@lzdongrui.com
 * @className CustomLongConverter
 * @since 2023-01-07
 */
public class CustomLongConverter extends StdSerializer<Long> {
    public CustomLongConverter() {
        super(Long.class);
    }
    @Override
    public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
        if (value.toString().length() > 12) {
            gen.writeString(value.toString());
//            log.info("the Long value is to long. will convert to String");
        } else {
            gen.writeNumber(value);
        }
    }
}
